#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e3 + 10, M = 1e4 + 10;
int n, m;
LL w[N];
LL g[N][N];
LL dis[N];
bool st[N];
void dij()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	for (int i = 0; i < n; i++) {
		int t = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[t] > dis[j])) {
				t = j;
			}
		}
		st[t] = 1;
		for (int j = 1; j <= n; j++) {
			if (dis[j] > dis[t] + g[t][j]) {
				dis[j] = dis[t] + g[t][j];
				//pre[j] = t;
			}
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}
	memset(g, 0x3f, sizeof(g));
	while (m--) {
	    LL a, b, c;
		cin >> a >> b >> c;
		g[a][b] = g[b][a] = min(g[a][b], c);
	}
	for (int i = 1; i <= n - 1; i++) {
		for (int j = 1; j <= n - 1; j++) {
			if (i == j)continue;
			g[i][j] += w[j];
		}
	}
	//cout << g[1][2] << endl;
	dij();
	/*int k = 1;
	int ans = 0;
	for (int i = n; i != 1; i = pre[i]) {
		ans += w[i];
	}
	ans += dis[n];*/
	cout << dis[n] << endl;
	return 0;
}